<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/23
 * Time: 14:14
 */

namespace app\admin\controller\system;


use app\common\controller\AdminController;
use think\app;
use think\facade\Session;

class Message extends AdminController
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = app('app\common\model\system\SystemAdmin');

    }
    public function index()
    {
        $id = Session::get('admin');
        $groups = $this->model->field('id,message,message_state,first_message,first_message_state')->where('id',$id['id'])->find();

        return View('',['row'=>$groups]);
    }

    public function edit(){

        $param= $this->request->param();

        try{
            $row = $this->model->where('id',$param['id'])->find();
            if(isset($param['message_state']) && $param['message_state']==1){
                $param['message_time'] = time();
            }

            if(isset($param['first_message_state']) && $param['first_message_state']==1){
                $param['first_message_time'] = time();
            }
                    
            $row->save($param);

        }catch (\Exception $exception){
            return json(['code'=>1,'msg'=>$exception->getMessage()]);
        }
        return json(['code'=>0,'msg'=>'修改成功']);
    }


}